<template>
	<view>
		<view class="editaddress border-radius margin-bottom-com ">
			<view class="content">
				<view class="" style="width: 100%;">
					<view class="margin-com flex-row-st" style="font-weight: bold;">地址信息</view>
					<view class="margin-tb-com flex-row-st" style="margin-left: auto;">默认</view>
					<view class="margin-tb-com" style=";">
						<switch :color="colors" style="transform:scale(0.7)" @change="switchChange"
							:checked="addressData.defaultFlag == 1"></switch>
					</view>
				</view>
				<view class="row">
					<view class="nominal">收件人</view>
					<view class="input"><input placeholder="收件人名字" v-model="addressData.receiver" type="text" />
					</view>
				</view>
				<view class="row">
					<view class="nominal">手机号</view>
					<view class="input"><input placeholder="手机号" v-model="addressData.phone" type="number"
							maxlength="11" /></view>
				</view>
				<!--                <view class="row">
                    <view class="nominal">所在地区</view>
                    <view class="input selectcity" @tap="openPicker">
                        <input placeholder="省、市、区、街道" disabled type="text" v-model="addressData.address" />
                        <view class="flex-row-ct" style="margin-left: auto;">
                        		<view class="flex-row-ct iconfont icon-you margin-right-com"
                        		style="font-size: 10px;margin-left: auto;color:#8E8E8E"></view>
                        </view>
                    </view>
                </view> -->
				<view class="row">
					<view class="nominal">详细地址</view>
					<view class="input"><textarea style="font-size: 28upx;" v-model="addressData.address"
							auto-height="true" placeholder="小区、写字楼、门牌号等" v-if="show == false"></textarea>
						<view class="flex-row-ec theme-color iconfont icon-dingwei1 margin-right-com"
							style="font-size: 35rpx;margin-left: auto;" @click="onMap"></view>
					</view>
				</view>
				<view class="flex-row-st margin-bottom-com" style="height: 100rpx;font-size: 25rpx;">
					<!-- 					<view class="margin-lr-com" style="">地址标签</view>
					<view class="flex-row-ct">
						<view class="flex-row-ct theme-bg-color" style="border-radius:50%;width:80rpx;height:80rpx;color:#fff;margin-right:15rpx">家</view>
						<view class="flex-row-ct theme-bg-color" style="border-radius:50%;width:80rpx;height:80rpx;color:#fff;margin-right:15rpx">公司</view>
						<view class="flex-row-ct theme-bg-color" style="border-radius:50%;width:80rpx;height:80rpx;color:#fff;margin-right:15rpx">学校</view>
						<view class="flex-row-ct theme-bg-color" style="border-radius:50%;width:80rpx;height:80rpx;color:#fff;margin-right:15rpx">父母</view>
						<view class="flex-row-ct theme-bg-color" style="border-radius:50%;width:80rpx;height:80rpx;color:#fff;margin-right:15rpx">朋友</view>
						<view class="flex-row-ct theme-bg-color" style="border-radius:50%;width:80rpx;height:80rpx;color:#fff;margin-right:15rpx">自定义</view>
					</view> -->
				</view>
				<view style="height:150rpx;background-color: red;"></view>
				<!--                <view class="row">
                    <view class="nominal" style="color: 666;margin-top: 10upx;">设为默认地址</view>
                    <view class="input switch">
                        <switch :color="colors" style="transform:scale(0.8)" @change="switchChange"
                            :checked="addressData.isdefult == 1"></switch>
                    </view>
                </view> -->
			</view>


			<!-- 省市区选择 province city area初始省市区设置 show:是否显示  @sureSelectArea：确认事件 @hideShow：隐藏事件-->
			<cc-selectCity :province="province" :city="city" :area="area" :show="show" @changeClick="changeClick"
				@sureSelectArea="onsetCity" @hideShow="onhideShow"></cc-selectCity>

		</view>
		<!-- 底部导航栏 -->
		<view class="" style="height:80px;"></view>
		<view @click="baocun" class="tabbar flex-row-st "
			style="position: fixed; bottom: 0; left: 0; right: 0;width:100%;height:60px;background-color: #fff;">
			<view class="save margin-lr-com" :style="'background:' + colors">保存</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { ref } from 'vue';
	import { deliveryAddressadd } from '../../api/shop/shop';

	const colors = ref('#EE3F4D');
	const show = ref(false);
	const province = ref("江西省");
	const city = ref("鹰潭市");
	const area = ref("余江区");
	const isShow = ref(true);
	const addressData = ref({
		receiver: '',
		phone: '',
		address: '',
		defaultFlag: 1,
	})

	const openPicker = () => {
		console.log('执行打开地址选择器')
		show.value = true
	}

	const changeClick = (value, value2, value3) => {

		console.log('地址选择器 = ' + value + value2 + value3);

		province.value = value;
		city.value = value2;
		area.value = value3;

	}
	const onhideShow = () => {
		show.value = false
		console.log('执行了关闭地址选择器')
	}
	//选中省市区
	const onsetCity = (e) => {
		let data = e.detail.target.dataset;
		let address = data.province + data.city + data.area;
		show.value = false
		addressData.address = address
	}
	//
	const switchChange = (e) => {
		addressData.value
	}
	const onMap = () => { }
	// 保存
	const baocun = () => {
		deliveryAddressadd(addressData.value).then(res => {
			console.log(res.data)
			if (res.code === 200) {
				uni.showToast({
					title: '保存成功',
					icon: "success"
				})
			}
			setTimeout(() => {
				uni.navigateBack()
			}, 1000)
		})
	}
</script>
<style lang="scss" scoped>
	page {
		background-color: #fff;
	}

	.tabbar {
		box-shadow: $uni-shadow-lg;
	}

	.editaddress {
		// background-color: #fff;
		// margin-left: 10rpx;
		// margin-right: 10rpx;
	}

	.save {
		width: 100%;
		color: #fff;
		height: 70rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		border-radius: 10rpx;
	}

	.save view {
		display: flex;
	}

	.content {
		display: flex;
		flex-wrap: wrap;
	}

	.content view {
		display: flex;
	}

	.content .row {
		width: 100%;
		margin-left: 4%;
		margin-bottom: 4%;
		//border-bottom: solid 1upx #eee;
	}

	.content .row .nominal {
		width: 20%;
		height: 80upx;
		font-size: 28upx;
		font-family: Droid Sans Fallback;
		font-weight: 400;
		color: rgba(51, 51, 51, 1);
		align-items: center;
	}

	.content .row .input {
		width: 77%;
		padding: 20upx 0;
		align-items: center;
		font-size: 28upx;
		background-color: #f7f7f7;
		border-radius: 15rpx;
	}

	.content .row .input input {
		font-size: 28upx;
		color: #333333;
		margin-left: 20upx;
	}

	.content .row .input textarea {
		min-height: 40upx;
		line-height: 40upx;
		margin-left: 20upx;
	}

	.content .del_box {
		width: 100%;
		display: block;
		overflow: hidden;
		margin-right: 30upx;
	}

	.content .del {
		width: 240upx;
		height: 80upx;
		float: right;
		justify-content: center;
		align-items: center;
		font-size: 28upx;
		color: #F23A3A;
		margin: 0 auto;
		margin-top: 50upx;
		border-radius: 38upx;
		background-color: rgba(255, 0, 0, 0.05);
		border-bottom: solid 1upx #eee;
	}

	.selectcity input {
		width: 90%;
	}

	.selectcity image {
		width: 40upx;
		height: 40upx;
		float: right;
	}
</style>